<template>
    <el-button type="primary" @click="openSave=true">
        <el-icon>
            <Plus/>
        </el-icon>
        新增
    </el-button>
    <el-dialog :model-value="openSave"
               :lock-scroll="false"
               append-to-body
               @close="closeSave"
               title="新增" width="50%">
        <el-form
                label-width="auto"
                :model="${ignoreFirstHumpName}Model">
            <#list tableFields as field>
                <el-form-item required label="${field.comment}">
                    <el-input v-model="${ignoreFirstHumpName}Model.${field.name}" placeholder="${field.comment}" clearable/>
                </el-form-item>
            </#list>
            <el-form-item>
                <el-button type="primary" @click="save${humpName}Action">新增</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script setup>
    import {save${humpName}} from "@/api/${serviceName}/${humpName}Api.js";
    import {clearProperty} from "@/util/Func.js";
    import {ElMessage} from "element-plus";
    import {useSearchStore} from "@/store/SearchStore.js";
    import {Plus} from "@element-plus/icons-vue";
    import {ref} from "vue";

    const searchStore = useSearchStore()
    const openSave = ref(false)
    const ${ignoreFirstHumpName}Model = ref({
    <#list tableFields as field>
        ${field.name}: '',
    </#list>
    })

    const closeSave = () => {
        openSave.value = false
    }

    const save${humpName}Action = () => {
        save${humpName}(${ignoreFirstHumpName}Model.value).then(res => {
            ${ignoreFirstHumpName}Model.value = clearProperty(${ignoreFirstHumpName}Model.value)
            ElMessage.success(res.message)
            closeSave()
        }).finally(() => {
            searchStore.noticePageRefresh()
        })
    }

</script>
